<template>
  <div class="container credit">
    <div class="flexbox credit-header">
      <div class="flexbox-item">
        <router-link to="commission/order" class="credit-btn">
          <span>积分记录</span>
          <van-icon name="description" />
        </router-link>
      </div>
      <div class="flexbox-item">
        <h2 class="credit-own">2000</h2>
        <p>我的积分</p>
        <div class="award-tips">今日可获取奖励</div>
      </div>
      <div class="flexbox-item">
        <router-link to="commission/order" class="credit-btn">
          <van-icon name="question2" />
          <span>积分规则</span>
        </router-link>
      </div>
    </div>

    <van-swipe :loop="false" :autoplay="1113000" class="van-swipe-low">
      <van-swipe-item v-for="(item, index) in carousels" :key="index">
        <van-image :src="item.thumb" />
      </van-swipe-item>
    </van-swipe>
    <div class="goods-panel">
      <van-cell
        value="更多"
        title="积分兑好礼"
        :border="false"
        is-link
        center
        class="van-cell-prefix-border"
      />
      <van-row type="flex" justify="space-around">
        <van-col span="12" v-for="(item, index) in goods" :key="index">
          <div class="exchange-goods" :style="'background-image:url('+item.thumb+');'">
            <h2>{{item.title}}</h2>
            <p>{{item.price}}积分起</p>
          </div>
        </van-col>
      </van-row>
    </div>
    <div class="goods-panel mt10">
      <van-cell title="轻松赚积分" :border="false" center class="van-cell-prefix-border" />
      <van-cell-group class="task-cell">
        <van-cell
          :title="item.title"
          :value="'+'+item.credit+'积分'"
          center
          is-link
          class="van-cell-media"
          v-for="(item, index) in task"
          :key="index"
        >
          <template slot="icon">
            <van-image :src="item.thumb" class="van-cell-media-fillet-icon" />
          </template>
        </van-cell>
      </van-cell-group>
    </div>
    <div class="bg-white mt10">
      <van-cell title="热门活动" :border="false" center class="van-cell-prefix-border" />
      <van-row>
        <van-col span="12" v-for="(item, index) in activity" :key="index">
          <div class="activity" v-on:click.native="redirect('goods/:id', item.id)">
            <img :src="item.thumb" />
            <h3>{{item.title}}</h3>
            <p>{{item.description}}</p>
          </div>
        </van-col>
      </van-row>
    </div>
  </div>
</template>
<script>
import {
  Row,
  Tag,
  Col,
  Icon,
  Cell,
  CellGroup,
  Popup,
  Button,
  Panel,
  Image,
  PullRefresh,
  Lazyload,
  Swipe,
  SwipeItem,
  Card,
  List
} from 'vant'

export default {
  components: {
    [Row.name]: Row,
    [Tag.name]: Tag,
    [Col.name]: Col,
    [Icon.name]: Icon,
    [Cell.name]: Cell,
    [CellGroup.name]: CellGroup,
    [Panel.name]: Panel,
    [Image.name]: Image,
    [Popup.name]: Popup,
    [Button.name]: Button,
    [Swipe.name]: Swipe,
    [SwipeItem.name]: SwipeItem,
    [PullRefresh.name]: PullRefresh,
    [Lazyload.name]: Lazyload,
    [Card.name]: Card,
    [List.name]: List
  },

  data () {
    return {
      carousels: [],
      goods: [],
      task: [],
      activity: [],
      icon: 'https://gitee.com/uploads/14/637814_77252102.png?1481090376'
    }
  },

  created () {
    this.axios
      .get('/credit')
      .then(response => {
        this.carousels = response.data.carousels
        this.goods = response.data.goods
        this.task = response.data.task
        this.activity = response.data.activity
      })
      .catch(function (error) {
        console.log(error)
      })
  },

  methods: {}
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="less" scoped>
.tips {
  background: #d8e8f8;
  color: #047bb3;
  font-size: 0.2rem;
  margin: 0;
  padding: 0.2rem 0.3rem;
  text-align: center;
  font-weight: normal;
}

.activity {
  padding: 10px;
  text-align: center;
  img {
    width: 50%;
  }
  h3 {
    margin: 0;
    font-size: 14px;
    font-weight: 500;
    color: #333;
  }
  p {
    margin: 10px 0 0;
    font-size: 5px;
    color: #ccc;
  }
}

.exchange-goods {
  position: relative;
  background-size: cover;
  background-position: center;
  padding: 10px;
  color: rgba(255, 255, 255, 0.9);
  text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.2);
  border-radius: 5px;
  margin: 0 7.5px;
  h2 {
    margin: 0;
    font-size: 15px;
    font-weight: 500;
  }
  p {
    margin: 0;
    font-size: 10px;
    color: rgba(255, 255, 255, 0.6);
  }
}
.news-content {
  position: relative;
  width: 100%;
  overflow: hidden;
  line-height: 1;
  height: 0;
  padding-bottom: 100%;
  background: #000000;
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  justify-content: center;
  align-items: center;
}
.news-content img {
  width: 100%;
  margin: auto;
}
.news-content div {
  width: 100%;
  height: 100%;
}
.news-content span {
  position: absolute;
  right: 0.1rem;
  bottom: 0.1rem;
}
.news-list {
  padding-top: 0;
}
.news-list /deep/ .van-cell-text {
  line-height: 0.44rem;
  font-size: 0.32rem;
  color: #666666;
}

.news-list .flexbox {
  font-size: 0;
}

.tsline-thumb /deep/ {
  padding: 0 0 2px;
}
.tsline-thumb /deep/ .van-cell__title {
  -webkit-box-flex: 1.38;
  -ms-flex: 1.38;
  flex: 1.38;
  order: 1;
  align-self: center;
}
.tsline-thumb /deep/ .van-cell__title div {
  padding: 0 10px;
}
.goods-title {
  font-size: 15px;
  color: #121212;
  font-weight: 500;
}

.goods-desc {
  font-size: 12px;
  color: #747474;
  line-height: 1.5;
  margin: 6px 0;
  overflow: hidden;
  word-break: break-all;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  /*! autoprefixer: off */
  -webkit-box-orient: vertical;
  /* autoprefixer: on */
}
.goods-desc span {
  color: #f60;
  padding-right: 2px;
}

.goods-price {
  color: #f60;
  font-size: 18px;
}

.news-exts {
  width: 100%;
  text-align: left;
  padding: 0.15rem 0 0;
  max-height: 0.75rem;
  overflow: hidden;
  font-weight: 300;
}
.news-exts span {
  font-size: 0.21rem;
  display: inline-block;
}
.news-exts span:not(.van-tag) {
  color: #aaa;
}
.news-exts span.van-tag {
  padding: 0.02rem 0.04rem;
}
.news-exts span.hsbar {
  width: 0.1rem;
  text-align: center;
}

.news-exts /deep/ .van-button--mini {
  width: 0.3rem;
  position: absolute;
  right: 0.1rem;
  border-radius: 0.2rem;
}

.tsline-thumb .news-exts {
  position: absolute;
  left: 0;
  bottom: 0;
}
.goods-panel {
  background: white;
  /deep/ .van-row.van-row--flex {
    padding: 15px 7.5px;
  }
}

.goods-panel /deep/ .van-cell__value span {
  font-size: 85%;
  color: #999;
  vertical-align: middle;
}
.goods-list {
  padding: 15px 7.5px;
}
.vertical-card {
  padding: 0 7.5px;
  display: block;
  height: auto;
  background: transparent;
}
.vertical-card /deep/ .van-card__thumb {
  display: block;
  position: initial;
  width: 100%;
  height: auto;
}
.goods-info {
  padding: 0.1rem 0;
}
.goods-info > h3 {
  margin: 0.1rem 0;
  font-size: 0.3rem;
  color: #666;
}
.goods-info > p {
  margin: 0;
  font-size: 0.26rem;
  font-weight: normal;
  color: #666;
}
.goods-info > p .goods-price {
  color: #ff7220;
  padding-right: 0.05rem;
}
</style>
